
package com.joysuch.wwyt.datadump.biz.query;

import cn.zlg.common.datadump.condition.QueryCondtionDef;
import cn.zlg.common.datadump.condition.QueryFieldCondition;
import cn.zlg.common.datadump.condition.QueryFieldConditionSet;
import cn.zlg.common.datadump.condition.SortFieldDef;
import com.joysuch.wwyt.mh.entity.dsl.QMhMonitoringPoint;
import com.joysuch.wwyt.risk.entity.dsl.QRiskDistrict;
import com.querydsl.core.types.Order;

import java.util.Arrays;
import java.util.List;

public class RiskDistrictDumpQueryBean implements QueryCondtionDef {

    @Override
    public List<QueryFieldConditionSet> getConditionSet() {
        return Arrays.asList(
                QueryFieldConditionSet.Builder().names("name", "nameOrCode").or(
                        new QueryFieldCondition("nameOrCode", QRiskDistrict.riskDistrict, QRiskDistrict.riskDistrict.code,
                                QRiskDistrict.riskDistrict.id, "contains"),
                        new QueryFieldCondition("nameOrCode", QRiskDistrict.riskDistrict, QRiskDistrict.riskDistrict.name,
                                QRiskDistrict.riskDistrict.id, "contains")
                ).build(),
                QueryFieldConditionSet.Builder().names("state").or(
                        // 当前实现，必须把有参数的条件放在最前面，否则会导致失败
                        new QueryFieldCondition("state", QRiskDistrict.riskDistrict, QRiskDistrict.riskDistrict.state,
                                QRiskDistrict.riskDistrict.id, "ne"),
                        new QueryFieldCondition("state", QRiskDistrict.riskDistrict, QRiskDistrict.riskDistrict.state,
                                QRiskDistrict.riskDistrict.id, "isNull")
                ).build()
        );
    }

    @Override
    public QueryFieldCondition[] getAllConditionDef() {
        return new QueryFieldCondition[] {
                new QueryFieldCondition("ids", QRiskDistrict.riskDistrict, QRiskDistrict.riskDistrict.id,
                        QRiskDistrict.riskDistrict.id, "in"),
                 };
    }

    @Override
    public SortFieldDef[] getAllSortFieldDef() {
        return new SortFieldDef[] {
                new SortFieldDef(QRiskDistrict.riskDistrict.id, "name", Order.DESC, true),
                new SortFieldDef(QRiskDistrict.riskDistrict.name, "name", Order.ASC)
        };
    }
}
